package com.cyandpos.pad.pay.model;



import com.cyandpos.pad.R;
import com.cyandpos.pad.common.commondata.ErpCommonData;
import com.cyandpos.pad.common.commondata.PaymentIdConstant;
import com.cyandpos.pad.common.commondata.SktConfigConstant;
import com.cyandpos.pad.posdata.Payment;
import com.cyandpos.pad.posdata.Sktconfig;

import java.util.ArrayList;
import java.util.List;

/**
 * 款台收款 Model 实现
 */

public class ICashCollectionModelImpl implements ICashCollectionModel {
    private List<Payment> skfs = new ArrayList<Payment>();
    private List<Integer> select_imgs = new ArrayList<Integer>();
    private List<Integer> imgs = new ArrayList<Integer>();

    List<Payment> skfs_test = new ArrayList<Payment>();

    @Override
    public void loadPayData(PayOnLoadListener listener) {
        skfs.clear();
        select_imgs.clear();
        imgs.clear();
        if (ErpCommonData.loadConfig != null && ErpCommonData.loadConfig.getPayList() != null) {
            boolean isHasBMQ = false;
            boolean isHasYHQK = false;
            for (Payment item : ErpCommonData.loadConfig.getPayList()) {
                switch (item.getPayType()) {
                    case Payment.SKFS_YHQK: {//卡券合并(包括编码券)
                        if(!isHasBMQ){
                            if(item.getIsCoded() == 1 ){//编码券
                                isHasBMQ = true;
                            }
                        }
                        if(!isHasYHQK){
                            if(item.getIsCoded() !=1 ){//电子卡券
                                isHasYHQK = true;
                            }
                        }
                    }
                    break;
                    case Payment.SKFS_NORMAL: {// 现金

                        skfs.add(item);
                    }
                    break;
                    case Payment.SKFS_WX: {// 微信

                        skfs.add(item);
                    }
                    break;

                    case Payment.SKFS_JH: {// 聚合
                        if (item.getPayCode() == 2){//支付宝

                            skfs.add(item);
                        }else if (item.getPayCode() == 3){//微信

                            skfs.add(item);
                        }else if (item.getPayCode() == 4){//银联

                            skfs.add(item);
                        }
                    }
                    break;
                    case Payment.SKFS_ZFB: { // 支付宝

                        skfs.add(item);
                    }
                    break;
                    case Payment.SKFS_YHK: {// 银行卡

                        skfs.add(item);
                    }
                    break;
                    case Payment.SKFS_CZK: {// 储值卡

                        skfs.add(item);
                    }
                    break;
                    case Payment.SKFS_YHQ: {// 优惠券纸券

                        skfs.add(item);
                    }
                    break;
                    case 106: {// 积分消费

                        skfs.add(item);
                    }
                    break;
                    case Payment.SKFS_FQBC:
                    case Payment.SKFS_MBDY:
                        break;
                    default:

                        skfs.add(item);
                        break;
                }
            }
            //卡券合并
            if (isHasYHQK) {
                Payment paymentKQ = new Payment(Payment.SKFS_YHQK);
                paymentKQ.setPayName("电子卡券");
                paymentKQ.setPayCode(9999);
                paymentKQ.setIsCoded(0);

                skfs.add(paymentKQ);
            }
            //编码券合并
            if (isHasBMQ) {
                Payment paymentBMQ = new Payment(Payment.SKFS_YHQK);
                paymentBMQ.setPayName("编码券一体");
                paymentBMQ.setPayCode(8888);
                paymentBMQ.setIsCoded(1);

                skfs.add(paymentBMQ);
            }
            //订金单
            String blFlag="";
            for(Sktconfig cItem: ErpCommonData.loadConfig.getSkt().getSktconfigList()){
                if(cItem.getLx().equals(SktConfigConstant.SKT_CONFIG_TYPE_PAYMENT) ){
                    if(cItem.getId().equals(PaymentIdConstant.SKT_CONFIG_PAYMENT_SETTING_DJD)){
                        blFlag = cItem.getValue();
                        break;
                    }
                }
            }
            if("0".equals(blFlag)) {
                Payment paymentDJD = new Payment(Payment.SKFS_DJD);
                paymentDJD.setPayName("订金单");
                paymentDJD.setPayCode(Payment.SKFS_DJD);
                skfs.add(paymentDJD);
            }
        }

        listener.onComplete(imgs,select_imgs,skfs);
    }

}
